/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.trainning.b2;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 *
 * @author Administrator
 */
public class Bai1DoiCoSo {
    private static Reader New;
    public static void main(String[] args) throws IOException {
        int a, b;
        try{
            BufferedReader br = new BufferedReader(new FileReader("B1Data.txt"));
            String s = br.readLine();
            a = Integer.parseInt(s);
            s = br.readLine();
            b = Integer.parseInt(s);
            if(a<0 || (b<=1 && b>36)) throw new NullPointerException();
            System.out.print("So a = "+a+" trong he co so b = "+b+" la: " );
            doiCoSo(a,b);
            System.out.println("");
            br.close();
        }catch(FileNotFoundException e){
            System.out.println("Không đọc được tệp");
        }catch(NumberFormatException e){
            System.out.println("Bạn hãy để mỗi số trên 1 dòng");
        }catch(NullPointerException e){
            System.out.println("0<a && 1<b<36");
        }catch(IOException e){
            System.out.println("Lỗi không xác định");
        }finally{
            
        }
        
    }
    public static void doiCoSo(int n,int base){
        if(n>=base) doiCoSo(n / base, base);
        if(n % base>9) System.out.printf("%c",n%base+55);
        else
        System.out.print((n % base));
    }
}
